<?Lassoscript
// Last modified 12/19/11 by ECL, Landmann InterActive

// FUNCTIONALITY
// Displays slider images

// CHANGE NOTES
// 12/19/11
// First implementation

// Debugging
// Var('svDebug' = 'Y');

// Initialize vars for nav control
Var('Records_Skipped' = 0);
If(Action_Param('skip'));
	$Records_Skipped = Action_Param('skip');
/If;
Var('This_Group' = Action_Param('group'));
Var('Records_Per_Page' = 15);
Var('Group_Size' = (Math_Mult(Var('Records_Per_Page'),5)));
Var('SkipCount' = integer);
Var('Records_Found' = integer);

// Initialize vars to display file matrix
Var('image_thumb_array' = array);
Var('LoopFrom' = integer);
Var('LoopTo' = integer);
Local('ThisPosition' = string);
Local('ThisPositionLink' = string);

// Initialize the vars to display the table
Var('column_limit' = 5);
Var('column_counter' = 0);
Var('row_counter' = 1);

// *************** START DELETE ***************
// If $Action=Delete and $vIntendedUse==Slider, delete the indicated file, then proceed
If(($vAction == 'Delete') && ($vIntendedUse == 'Slider'));

	// Look for delete errors
	Local('DeleteError' = false);

	// Delete the Slider
	File_Delete(($svSliderImagesPath)+($vID));
	If(File_CurrentError != 'No Error');
		#DeleteError = true;
	/If;
	Debug;
		('177: Delete Slider<br>\n');
		('177: Filepath = '+(($svSliderImagesPath)+($vID))+'<br>\n');
		('177: File_CurrentError = '+(File_CurrentError)+'<br>\n');
		('177: DeleteError = '+(#DeleteError)+'<br>\n');
	/Debug;

	// Set the error code
	If(#DeleteError == true);
		$vError = '1022';
		$vOption = File_CurrentError;
	Else;
		$vError = '1023';
		$vOption = $vIDOriginal;
	/If;

	// DELETE/MODIFY DATABASE ENTRIES
	Include(($svAdminHelpersPath)+'library_moddata.inc');

/If;
// *************** END DELETE ***************

// Get the Images directory listing
$image_thumb_array = File_ListDirectory($svSliderImagesPath);
If($image_thumb_array >> '.DS_Store');
	$image_thumb_array->(Remove:1);
/If;
If($image_thumb_array >> '.svn/');
	$image_thumb_array->(Remove:1);
/If;

// Get how many images in the array
Var('ImageCount' = $image_thumb_array->size);

// Do not display if the file is a secure file
If(($vError != '') && ($vIntendedUse == 'Slider'));
	LI_ShowError3(-ErrNum=(Var('vError')), -Option=(Var('vOption')));
/If;

// Debugging
// Var('svDebug' = 'Y');

// If array empty, dump out message
If($ImageCount == 0);
	'\t\t<div class="imagepanel" id="nifty2" style="margin-top:17px;">\n';
	'\t<h3 class="nifty">Slider Images</h3>\n';
	'\t\t\t<p class="nifty">No slider images found.</p>\n';
	'\t\t</div>\n';
Else;
	'\t\t<div class="imagepanel" id="nifty2" style="margin-top:17px;">\n';
	'\t<h3 class="nifty">Slider Images</h3>\n';
	'\t\t\t<p class="nifty">The slider images that have been uploaded to your site are displayed below.<br>\n</p>\n';
	$LoopTo = (Math_Add($Records_Skipped, $Records_Per_Page));
	$LoopFrom = (Math_Add($Records_Skipped, 1));
	Debug;
		('207: LoopFrom = '+($LoopFrom)+'<br>\n');
		('207: LoopTo = '+($LoopTo)+'<br>\n');
		('207: Records_Skipped = '+($Records_Skipped)+'<br>\n');
		('207: <strong>image_thumb_array</strong> = '+($image_thumb_array)+'<br>\n');
	/Debug;
	'<table width="100%" bgcolor="#F0F0F0">\n';
	'\t<tr>\n';
	$column_counter = 0;
	Loop(-From=$LoopFrom, -To=$LoopTo);
		$column_counter = (Math_Add($column_counter, 1));
		'\t\t<td>\n';
		'\t\t\t<div align="center">\n';
		Protect;
			#ThisPosition = ($image_thumb_array->Get(Loop_Count));
			Debug;
				('\t\t\t\ThisPosition = '+(#ThisPosition)+'<br>\n');
				('\t\t\t\tImageType = '+(#ImageType)+'<br>\n');
			/Debug;

		('\t\t\t\t<!-- 340 --><a href="'+($svSliderImagesPath)(#ThisPosition)+'" target="_blank"><img src="'+($svSliderImagesPath)(#ThisPosition)+'" alt="'+(#ThisPosition)+'" width="200"><br>\n');
		('\t\t\t\t'+(#ThisPosition)+'</a><br>\n');
		('\t\t\t\t<!-- 342 --><a href="'+($svAdminControllersPath)+($svLibraryPage)+'?ID='+(#ThisPosition)+'&Action=Delete&Datatype='+($vDataType)+'&ImageType='+(#ImageType)+'&IntendedUse=Slider" title="Delete this Image"><img src="'+($svImagesPath)+'trash_icon_12.png" width="12" height="15" alt="Trash Can Icon" align="middle"></a>\n');

		// Check Image Usage Link - Displays for every type of image
		'\t\t\t\t&nbsp;&nbsp;&nbsp;\n';
		('\t\t\t\t<!-- 350 --><a href="'+(($svAdminControllersPath)+($svCheckImageUsagePage))+'?Datatype='+($vDatatype)+'&ID='+(#ThisPosition)+'&height=450&width=500" class="thickbox" title="Check Usage of '+(#ThisPosition)+'"><img src="'+($svFileIconsPath)+'layout_link.png" width="16" height="16" alt="Layout Link Icon" align="middle"></a>\n');

		/Protect;
		'\t\t\t</div>\n';
		'\t\t</td>\n';
		// Add closing </tr> if end of column
		If($column_counter == $column_limit);
			'\t</tr><!-- 74 -->\n';
			$column_counter = 0;
			If(Loop_Count != $LoopTo);
				'\t<tr><!-- 77 -->\n';
			/if;
		/if;
	/Loop;
	'\t<tr>\n';
	('\t\t<td valign="middle" colspan="'+($column_limit)+'" align="center">');
	// Navigation control
	Include(($svAdminHelpersPath)+'nav_control_grid.inc');
	'\t\t</td>\n';
	'\t</tr>\n'
	'</table>\n';
	'\t\t</div>\n';

/If;
?> 